﻿//-----------------------------------------------------------------------
// <copyright file="IDispatcher.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>24/01/2013</date>
//-----------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using System.Windows.Threading;

namespace ConsoleHoster.Common.Utilities.Threading
{
	/// <summary>
	/// Represents a contract for invoking actions on the implementing IDispatcher instance
	/// This will be used for decoupling components from Dispatcher objects
	/// </summary>
	public interface IDispatcher
	{
		/// <summary>
		/// Checkes whether the execution is happening on the current dispatcher thread or not
		/// </summary>
		/// <returns>true, if the caller thread is the dispatcher thread. false - otherwise</returns>
		bool IsInDispatcherThread();

		/// <summary>
		/// Queues the given action for execution on the dispatcher thread
		/// </summary>
		/// <param name="argAction">The action to be executed on the dispatcher thread</param>
		Task BeginInvoke(Action argAction, DispatcherPriority argPriority = DispatcherPriority.Background);

		/// <summary>
		/// Invokes the given action on the current dispatcher thread
		/// </summary>
		/// <param name="argAction">The action to be executed</param>
		/// <exception cref="System.ArgumentNullException">Thrown, if the given action is null</exception>
		void Invoke(Action argAction, DispatcherPriority argPriority = DispatcherPriority.Normal);
	}
}
